package flc.ast.adapter;

import android.text.format.Formatter;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.media.MediaInfo;
import stark.common.basic.utils.MimeUtils;

public class DocumentsAdapter extends StkProviderMultiAdapter<MediaInfo> {

    private int currentFlag;

    public DocumentsAdapter() {
        addItemProvider(new DocumentsItemProvider());
    }

    public void setFlag(int flag) {
        currentFlag = flag;
    }

    private class DocumentsItemProvider extends BaseItemProvider<MediaInfo> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_documents;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MediaInfo mediaInfo) {
            ImageView ivDocumentsIcon = baseViewHolder.getView(R.id.ivDocumentsIcon);
            if (FileUtils.isDir(mediaInfo.getPath())) {
                ivDocumentsIcon.setImageResource(R.drawable.awenjian);
            } else if (MimeUtils.isImgMimeType(mediaInfo.getPath())) {
                ivDocumentsIcon.setImageResource(R.drawable.atupian2);
            } else if (MimeUtils.isVideoMimeType(mediaInfo.getPath())) {
                ivDocumentsIcon.setImageResource(R.drawable.aship);
            } else if (MimeUtils.isAudioMimeType(mediaInfo.getPath())) {
                ivDocumentsIcon.setImageResource(R.drawable.ayinp);
            } else if (mediaInfo.getPath().endsWith(".doc") || mediaInfo.getPath().endsWith(".docx")) {
                ivDocumentsIcon.setImageResource(R.drawable.adoc);
            } else if (mediaInfo.getPath().endsWith(".xls") || mediaInfo.getPath().endsWith(".xlsx")) {
                ivDocumentsIcon.setImageResource(R.drawable.axcl);
            } else if (mediaInfo.getPath().endsWith(".ppt") || mediaInfo.getPath().endsWith(".pptx")) {
                ivDocumentsIcon.setImageResource(R.drawable.appt);
            } else if (mediaInfo.getPath().endsWith(".zip")) {
                ivDocumentsIcon.setImageResource(R.drawable.ayasuobao);
            } else if (mediaInfo.getPath().endsWith(".pdf")) {
                ivDocumentsIcon.setImageResource(R.drawable.apdf);
            } else if (mediaInfo.getPath().endsWith(".txt")) {
                ivDocumentsIcon.setImageResource(R.drawable.atxt);
            } else {
                ivDocumentsIcon.setImageResource(R.drawable.aweizhwenj);
            }


            baseViewHolder.setText(R.id.tvDocumentsName, mediaInfo.getName());
            String phoneTime = TimeUtils.millis2String(mediaInfo.getDateModified() * 1000L, "yyyy/MM/dd");
            baseViewHolder.setText(R.id.tvDocumentsDate, phoneTime);
            baseViewHolder.setText(R.id.tvDocumentsSize, Formatter.formatFileSize(context, mediaInfo.getSize()));
        }
    }
}
